﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGinnBPM.Services;
using NGinnBPM.Runtime;
using NLog;
using NGinnBPM.Lib.Interfaces;

namespace NGinnBPM.Services.Persistence
{
    /// <summary>
    /// In-memory repository of task state. For testing purposes only.
    /// </summary>
    public class MemoryTaskInstanceRepository : ITaskInstanceRepository
    {
        private Dictionary<string, TaskInstance> _data = new Dictionary<string, TaskInstance>();
        #region ITaskInstanceRepository Members

        public NGinnBPM.Runtime.TaskInstance GetTaskInstance(string correlationId)
        {
            TaskInstance ti;
            return _data.TryGetValue(correlationId, out ti) ? ti : null;
        }

        public void UpdateTaskInstance(NGinnBPM.Runtime.TaskInstance inst)
        {
            _data.Remove(inst.InstanceId);
            _data[inst.InstanceId] = inst;
        }

        public void InsertTaskInstance(NGinnBPM.Runtime.TaskInstance inst)
        {
            _data.Add(inst.InstanceId, inst);
        }

        public IList<string> GetTaskInstancesReadyForProcessing(int maxNum)
        {
            throw new NotImplementedException();
        }

        public IDefaultTaskInstanceFactory TaskFactory { get; set; }
        public IProcessPackageRepository PackageRepository { get; set; }

        #endregion

        #region ITaskInstanceRepository Members


        public void UpdateTaskSchedulingStatus(string instanceId, TaskSchedulingStatus status, string additionalInfo)
        {
            throw new NotImplementedException();
        }

        public void SetWaitingTaskInstancesReady(string processDefinition, string taskId)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ITaskInstanceRepository Members


        public IList<string> FindProcessesByCorrelationId(string processCorrelationId, string definitionId)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
